<template>
  <div class="supply">
    <div class="header" v-if="!id">
      <hr>
       <div class="className">
          <span class="sp1">
            分类：
          </span>
          <ul class="conntentMsg">
            <li v-for="item in taglist" :key="item.id" @click="getHomeList(item)" :class="commdityId==item.id? 'active':''">
              <span>{{ item.label }}</span>
          </li>
          </ul>
       </div>
      <hr>
    </div>
    <ul v-loading="loading" style="min-height: 300px;">
      <li v-for="item in tableData" :key="item.id" class="goodsBox" @click="toSupply(item)">
        <div class="goods">
          <img :src="baseUrl+item.img" alt="">
          <div class="goods_info">
            <span class="goods_name">{{ item.name }}</span>
            <p class="goods_description">{{ item.description }}</p>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import homeApi from '@/api/apiHome';
 export default {
    data(){
      return {
        id:'',
        taglist:[],
        loading:false,
        tableData:[],
        baseUrl:'https://www.lucklylife.cn/api',
        commdityId:''
      }
    },
    methods:{
      async classification(){
        const result =  await homeApi.getClassification()
        this.taglist = result.data
      },
      getGoodslist(){
        this.loading = true
        homeApi.getAllgoods(this.commdityId).then(res=>{
          this.tableData = res.data
          this.loading = false
        })
      },
      getHomeList(item){
        this.commdityId = item.id
        this.getGoodslist()
      },
      toSupply(item){
        this.$router.push({path:'/wantToBuy',query:{id:item.id}})
      },
    },
    mounted(){
      this.id = this.$route.query.id;
      this.commdityId = this.$route.query.id;
      if(!this.id){
        this.classification();
      }
      this.getGoodslist();
    },
 }
</script>
<style scoped lang="less">
.header{
  margin-top: 10px;
  
}
.conntentMsg{
  margin-left: 20px;
  display: flex;
  justify-content: flex-start;
  li{
    margin: 10px;
    cursor: pointer;

  }
  li:hover{
    color: #007fff;
  }
}
.className{
  display: flex;
  justify-content: flex-start;

}
.goodsBox{
  border: 1px solid #ccc;
  border-radius: 5px;
  margin: 10px 0;
  overflow: auto;
  cursor: pointer;
  background-color: #fff;
}
.goods{
  display: flex;
  margin: 10px;
  justify-content: flex-start;

  img{
    width: 150px;
    height: 150px;
    border-radius: 3px;
  }
  .goods_info{
    margin-left: 20px;
    .goods_name{
      font-size: 18px;
      color: #666;
      margin-bottom: 10px;
    }
    .goods_description{
      font-size: 14px;
      line-height: 28px;
    }
  }
}
.sp1{
  font-size: 14px;
  color: #666;
  margin: 10px;
}
.active{
  color: #007fff;
}
</style>